<html>
<head><meta charset="utf-8"><title>Defining POFs · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html">Defining POFs</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199062492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199062492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199062492">(May 28 2020 at 18:27)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="1866">@WG-ffi-unwind</span> I'd appreciate feedback on this new section defining POF: <a href="https://github.com/BatmanAoD/project-ffi-unwind/blob/Rfc-POF-terminology/rfcs/0000-c-unwind-abi.md#plain-old-frames">https://github.com/BatmanAoD/project-ffi-unwind/blob/Rfc-POF-terminology/rfcs/0000-c-unwind-abi.md#plain-old-frames</a></p>



<a name="199063273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199063273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> acfoltzer <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199063273">(May 28 2020 at 18:33)</a>:</h4>
<p>I like that a lot. it seems very clear</p>



<a name="199063950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199063950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199063950">(May 28 2020 at 18:39)</a>:</h4>
<p>Thanks!</p>



<a name="199064976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199064976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199064976">(May 28 2020 at 18:47)</a>:</h4>
<p>Hm so maybe I misunderstood, but my understanding is that this "Note that a non-POF may become a POF, for instance if all Drop objects are moved out of scope," is maybe too simplistic?</p>
<p>In particular, for something like this:</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">c</span>: <span class="kt">bool</span><span class="p">,</span><span class="w"> </span><span class="n">v</span>: <span class="nc">Droppy</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">       </span><span class="n">std</span>::<span class="n">mem</span>::<span class="nb">drop</span><span class="p">(</span><span class="n">c</span><span class="p">);</span><span class="w"></span>
<span class="w">   </span><span class="p">}</span><span class="w"></span>
<span class="w">   </span><span class="n">call_thing_that_will_try_to_skip_this_frame</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>I believe we'll currently have a drop flag on the stack and as such the foo function is not POF even though all drop object are out of scope and won't drop</p>



<a name="199065161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199065161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199065161">(May 28 2020 at 18:48)</a>:</h4>
<p>I don't know the details of why we require POF -- so I'm not sure if the drop flag means UB. But we should be sure to clarify and either link to or include it in the RFC, IMO.</p>



<a name="199065222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199065222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199065222">(May 28 2020 at 18:49)</a>:</h4>
<p>(in the above <code>Droppy</code> implements Drop, to be clear)</p>



<a name="199067172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199067172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199067172">(May 28 2020 at 19:03)</a>:</h4>
<p>The intent is to specify frames that can be safely deallocated without executing any drop glue, whether or not drop glue would execute in "normal" unwinding. Deallocation without stopping at landing pads is probably most common with <code>longjmp</code>.</p>



<a name="199069617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199069617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199069617">(May 28 2020 at 19:22)</a>:</h4>
<p>For the example, it shouldn't be UB if <code>c</code> was <code>true</code>.</p>



<a name="199077612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199077612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199077612">(May 28 2020 at 20:01)</a>:</h4>
<p>oh, yes, sorry, I meant that c was true in that case -- note that drop glue <em>would get executed</em> in that case</p>



<a name="199077679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199077679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199077679">(May 28 2020 at 20:01)</a>:</h4>
<p>but that drop glue would look something like <code>if !was_dropped { ... }</code></p>



<a name="199077912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199077912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199077912">(May 28 2020 at 20:02)</a>:</h4>
<p>it seems like it should be true that this can be safely skipped, but I am not 100% sure that is always true -- it definitely seems like it relies a good bit on how that's structured exactly</p>



<a name="199078477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199078477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199078477">(May 28 2020 at 20:05)</a>:</h4>
<p>Perhaps the next step is to ask for confirmation from LLVM devs that skipping the cleanup there (or in an equivalent C++ scenario involving <code>longjmp</code>) is not UB?</p>



<a name="199080798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199080798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199080798">(May 28 2020 at 20:18)</a>:</h4>
<p>C++ doesn't have drop flags, destructors are always executed.</p>



<a name="199082256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199082256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199082256">(May 28 2020 at 20:28)</a>:</h4>
<p>Right - so the equivalent scenario would be a destructor that may or may not perform non-trivial cleanup depending on the object's state</p>



<a name="199082311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199082311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199082311">(May 28 2020 at 20:29)</a>:</h4>
<p>E.g., is it UB to unwind over a frame with a <code>unique_ptr</code> after it's been moved-from?</p>



<a name="199137211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199137211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199137211">(May 29 2020 at 10:34)</a>:</h4>
<p>Technically, yes. (Also I assume you meant longjmp instead of unwind)</p>



<a name="199168421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199168421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199168421">(May 29 2020 at 15:16)</a>:</h4>
<p>I also feel a bit of uncertainty around this question</p>



<a name="199168442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199168442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199168442">(May 29 2020 at 15:16)</a>:</h4>
<p>I suspect it's one of those that almost always works but I'm worried about edge cases</p>



<a name="199169301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199169301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199169301">(May 29 2020 at 15:23)</a>:</h4>
<p>Yes, sorry, I did mean <code>longjmp</code></p>



<a name="199169676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199169676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199169676">(May 29 2020 at 15:25)</a>:</h4>
<p>I realize it would be undefined according to the ISO C++ standard (due to the way "moved-from" objects are specified), but I'm curious whether LLVM provides stronger guarantees for a specific <code>unique_ptr</code> implementation (since we're not concerned with the specification of the C++ standard lib, but with the safety of skipping "trivial cleanup" operations)</p>



<a name="199233586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Defining%20POFs/near/199233586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Defining.20POFs.html#199233586">(May 30 2020 at 02:36)</a>:</h4>
<p>I'm tending towards allowing this. As long as the destructor is effectively a no-op, we can safely elide it. AFAIK LLVM doesn't perform any code transformations that might invalidate that.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>